<template>
  <div class="tabcard">
    <el-tag
      v-for="(tag, index) in tags"
      :key="tag.title"
      :closable="index != 0"
      :type="tag.type"
      @close="handleClose(tag)"
      @click="tabcardclick(tag)"
      v-show="tag.path != ''"
    >
      {{ tag.title }}
    </el-tag>
  </div>
</template>

<script>
export default {
  name: "tagcard",
  data() {
    return {
      tags: {},
      acitvepath: null,
    };
  },
  mounted() {
    this.tags = this.$store.state.tags;
  },
  activated() {
    console.log(this.$route);
    this.acitvepath = this.$route;
  },
  methods: {
    handleClose(tag) {
      this.$store.commit("deletetags", tag.id);
      console.log(this.$store.state.tags);
      console.log("删除");
      let mudi = this.$store.state.tags.find((item) => {
        return item.id == tag.id - 1;
      }).path; //删除后跳转id-1的路由或者跳转到首页
      this.$router.push(mudi == "" ? "/index/about" : mudi);
    },
    tabcardclick(tag) {
      //点击标签跳转到对应的路由
      console.log(tag);
      console.log(this.$route.path);
      if (tag.path != this.$route.path) {
        this.$router.push(tag.path);
      }
    },
  },
};
</script>

<style scoped>
.tabcard {
  width: 99.8%;
  margin-top: 3px;
  background-color: rgba(204, 230, 247, 0.671);
  border-color: #d9ecff;
  display: inline-block;
  height: 35px;
  line-height: 30px;
  font-size: 12px;
  color: #409eff;
  border-width: 1px;
  border-style: solid;
  border-radius: 4px;
  box-sizing: border-box;
}
.el-tag {
  margin-left: 5px;
  cursor: pointer;
}
</style>